package com.fwlst.module_home.dialog;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.fwlst.module_home.R;


public class BaseCommonDialog extends Dialog {
    private TextView titleTv;
    private TextView messageTv;
    private TextView negtiveBn;
    private TextView positiveBn;
    private String message;
    private String title;
    private String positive;
    private String negtive;
    private int imageResId = -1;
    private boolean isSingle = false;
    public OnClickBottomListener onClickBottomListener;

    public BaseCommonDialog(@NonNull Context context) {
        super(context, R.style.BaseCustomDialog);
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.base_custom_dialog);
        this.setCanceledOnTouchOutside(false);
        this.initView();
        this.refreshView();
        this.initEvent();
    }

    private void initEvent() {
        this.positiveBn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (BaseCommonDialog.this.onClickBottomListener != null) {
                    BaseCommonDialog.this.onClickBottomListener.onPositiveClick();
                }

            }
        });
        this.negtiveBn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (BaseCommonDialog.this.onClickBottomListener != null) {
                    BaseCommonDialog.this.onClickBottomListener.onNegtiveClick();
                }

            }
        });
    }

    private void refreshView() {
        if (!TextUtils.isEmpty(this.title)) {
            this.titleTv.setText(this.title);
            this.titleTv.setVisibility(VISIBLE);
        } else {
            this.titleTv.setVisibility(GONE);
        }

        if (!TextUtils.isEmpty(this.message)) {
            this.messageTv.setText(this.message);
        }

        if (!TextUtils.isEmpty(this.positive)) {
            this.positiveBn.setText(this.positive);
        } else {
            this.positiveBn.setText("确定");
        }

        if (!TextUtils.isEmpty(this.negtive)) {
            this.negtiveBn.setText(this.negtive);
        } else {
            this.negtiveBn.setText("取消");
        }

    }

    public void show() {
        super.show();
        this.refreshView();
    }

    private void initView() {
        this.negtiveBn = (TextView)this.findViewById(R.id.negtive);
        this.positiveBn = (TextView)this.findViewById(R.id.positive);
        this.titleTv = (TextView)this.findViewById(R.id.title);
        this.messageTv = (TextView)this.findViewById(R.id.message);
    }

    public BaseCommonDialog setOnClickBottomListener(OnClickBottomListener onClickBottomListener) {
        this.onClickBottomListener = onClickBottomListener;
        return this;
    }

    public String getMessage() {
        return this.message;
    }

    public BaseCommonDialog setMessage(String message) {
        this.message = message;
        return this;
    }

    public String getTitle() {
        return this.title;
    }

    public BaseCommonDialog setTitle(String title) {
        this.title = title;
        return this;
    }

    public String getPositive() {
        return this.positive;
    }

    public BaseCommonDialog setPositive(String positive) {
        this.positive = positive;
        return this;
    }

    public String getNegtive() {
        return this.negtive;
    }

    public BaseCommonDialog setNegtive(String negtive) {
        this.negtive = negtive;
        return this;
    }

    public int getImageResId() {
        return this.imageResId;
    }

    public boolean isSingle() {
        return this.isSingle;
    }

    public BaseCommonDialog setSingle(boolean single) {
        this.isSingle = single;
        return this;
    }

    public BaseCommonDialog setImageResId(int imageResId) {
        this.imageResId = imageResId;
        return this;
    }

    public interface OnClickBottomListener {
        void onPositiveClick();

        void onNegtiveClick();
    }
}